<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该问卷，请重新选择！','error','jy_wenjuan/myhome/');
	}
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['needdesc']=true;
	pdo_update('jy_wenjuan_list',array('readnum +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$item=pdo_get('jy_wenjuan_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$this->session('dati_id',$_RQ['id']);
	$canyu=pdo_get('jy_wenjuan_log',array('issub'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'datiid'=>$_RQ['id']));
	if($canyu['id']){
		$canyu['content']=json_decode($canyu['content'],true);
		$return['nowkey']=intval($canyu['nowkey']);
		$return['nowitem']=$canyu['content'][$return['nowkey']];
		$item['content']=$canyu['content'];
	}else{
		$tikus=$this->model('diaocha')->gettikus($item);
		$insert=array(
			'datiid'=>$_RQ['id'],
			'allscore'=>$item['allscore'],
			'type'=>$item['type'],
			'content'=>$tikus,
		);
		if(count($tikus)){
			$canyu['id']=$this->model('diaocha')->add_canyu($insert);
		}
		$return['nowkey']=intval($_RQ['nowkey']);
		$return['nowitem']=$tikus[$return['nowkey']];
		$item['content']=$tikus;
		$canyu['content']=$tikus;
	}
	$item['content']=array_values($item['content']);
	foreach($item['content'] as &$v){
		$v['typetitle']=$this->ti_types[$v['type']];
	}
	$return['allnum']=count($item['content']);
	$item['workers']=json_decode($item['workers'],true);
	$return['item']=$item;
	$return['banner']=json_decode($item['hdp'],true);
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['desc'],
		'link'=>custom_url('jy_wenjuan/diaocha/id='.$item['id'],true),
		'imgUrl'=>tomedia($item['image']),
	);
	set_html('title',$item['title']);
	$return['post']=array('id'=>$canyu['id'],'nowkey'=>$return['nowkey'],'content'=>$item['content']);
	$return['post']['name']=$member['nickname'];
	$return['member']=$member;
	$return['danan_key']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='update'){
	$postdata=get_postdata();
	if($postdata){
		$this->model('diaocha')->up_canyu($postdata);
	}
	exi('success');
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('请先提交！客户姓名','error');
	}
	$getscore=$this->model('diaocha')->getscore($postdata['content']);
	pdo_update('jy_wenjuan_log',array('issub'=>1,'allscore'=>$getscore['allscore'],'score'=>$getscore['score'],'content'=>ijson_encode($getscore['content'])),array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['id']));
	exi('提交问卷成功','','jy_wenjuan/myhome/');
}